package com.lc.projects.structure.tree;

public class BinaryTree2<T> {
	private TreeNode<T> root = null;
	
	public TreeNode<T> getRoot() {
		return root;
	}

	public void setRoot(TreeNode<T> root) {
		this.root = root;
	}

	public BinaryTree2(TreeNode<T> root) {
		this.root = root;
	}

	public void addLeftChild(BinaryTree2<T> leftChild) {
		root.setLeftChild(leftChild.root);
	}

	public void addRightChild(BinaryTree2<T> rightChild) {
		root.setRightChild(rightChild.root);
	}

	public boolean isEmpty() {
		return root == null;
	}

	public void inOrder(TreeNode<T> subTree) {
		if (subTree != null) {
			inOrder(subTree.getLeftChild());
			visit(subTree);
			inOrder(subTree.getRightChild());
		}
	}

	private void visit(TreeNode<T> subTree) {
		System.out.println(subTree);
	}

}

class TreeNode<T> {
	private T data;

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public TreeNode<T> getLeftChild() {
		return leftChild;
	}

	public void setLeftChild(TreeNode<T> leftChild) {
		this.leftChild = leftChild;
	}

	public TreeNode<T> getRightChild() {
		return rightChild;
	}

	public void setRightChild(TreeNode<T> rightChild) {
		this.rightChild = rightChild;
	}

	public boolean isVisited() {
		return visited;
	}

	public void setVisited(boolean visited) {
		this.visited = visited;
	}

	private TreeNode<T> leftChild;
	private TreeNode<T> rightChild;
	private boolean visited = false;

	public TreeNode() {
	}

	public TreeNode(T data) {
		this.data = data;
		this.leftChild = null;
		this.rightChild = null;
	}

	@Override
	public String toString() {
		return "TreeNode [data=" + data + "]";
	}

}
